<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
      <!--<el-form-item label="行业编号" prop="industryNum">-->
        <!--<el-input v-model="dataForm.industryNum" placeholder="行业编号"></el-input>-->
      <!--</el-form-item>-->
      <el-form-item label="行业名称" prop="industryName">
        <el-input v-model="dataForm.industryName" placeholder="字典类型名称 - 如:用户性别"></el-input>
      </el-form-item>
      <el-form-item label="行业简介" prop="remark">
        <el-input v-model="dataForm.remark" type="textarea" placeholder="行业简介"></el-input>
      </el-form-item>
      <el-form-item label="状态 " prop="status">
        <template>
          <el-radio-group v-model="dataForm.status">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="2">禁用</el-radio>
          </el-radio-group>
        </template>
      </el-form-item>
      <!-- <el-form-item label="创建人" prop="createUser">
         <el-input v-model="dataForm.createUser" placeholder="创建人"></el-input>
       </el-form-item>
       <el-form-item label="创建时间" prop="createTime">
         <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
       </el-form-item>
       <el-form-item label="修改人" prop="updateUser">
         <el-input v-model="dataForm.updateUser" placeholder="修改人"></el-input>
       </el-form-item>
       <el-form-item label="修改时间" prop="updateTime">
         <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
       </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          industryId: 0,
          industryNum: '',
          industryName: '',
          remark: '',
          status: 1,
          createUser: '',
          createTime: '',
          updateUser: '',
          updateTime: ''
        },
        dataRule: {
          industryNum: [
            {required: true, message: '行业编号不能为空', trigger: 'blur'}
          ],
          industryName: [
            {required: true, message: '字典类型名称 - 如:用户性别不能为空', trigger: 'blur'}
          ],
          remark: [
            {required: true, message: '行业简介不能为空', trigger: 'blur'}
          ],
          status: [
            {required: true, message: '状态  0：禁用   1：正常不能为空', trigger: 'blur'}
          ],
          createUser: [
            {required: true, message: '创建人不能为空', trigger: 'blur'}
          ],
          createTime: [
            {required: true, message: '创建时间不能为空', trigger: 'blur'}
          ],
          updateUser: [
            {required: true, message: '修改人不能为空', trigger: 'blur'}
          ],
          updateTime: [
            {required: true, message: '修改时间不能为空', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.industryId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.industryId) {
            this.$http({
              url: this.$http.adornUrl(`/operate/industry/info/${this.dataForm.industryId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.industryNum = data.industry.industryNum
                this.dataForm.industryName = data.industry.industryName
                this.dataForm.remark = data.industry.remark
                this.dataForm.status = data.industry.status
                this.dataForm.createUser = data.industry.createUser
                this.dataForm.createTime = data.industry.createTime
                this.dataForm.updateUser = data.industry.updateUser
                this.dataForm.updateTime = data.industry.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/operate/industry/${!this.dataForm.industryId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData(
                {
                  'industryId': this.dataForm.industryId || undefined,
                  'industryNum': this.dataForm.industryNum,
                  'industryName': this.dataForm.industryName,
                  'remark': this.dataForm.remark,
                  'status': this.dataForm.status,
                  'createUser': this.dataForm.createUser,
                  'createTime': this.dataForm.createTime,
                  'updateUser': this.dataForm.updateUser,
                  'updateTime': this.dataForm.updateTime
                })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
